#include <stdio.h>
#include <stdlib.h>
/* #include <mcheck.h> */
#include <err.h>
#include "./lib/cr.h"
#include "./lib/cw.h"

int main(void){
  cr c1;
  cw c2;
  Tuple e;

/* #ifndef NDEBUG */
/*   mtrace (); */
/* #endif */

  c1 = cr_create("pru.txt");

  if (c1 == NULL)
    errx(EXIT_FAILURE, "Error al crear cinta de lectura"
	 ", archivo %s, linea %i", __FILE__, __LINE__);
  
  c2 = cw_create("pruw.txt");
  if (c2 == NULL){
    c1 = cr_destroy(c1);
    errx(EXIT_FAILURE, "Error al crear cinta de escritura" 
	 ", archivo %s, linea %i", __FILE__, __LINE__);
  }
    
  cr_arr(c1);

  cw_arr(c2);

  while (!cr_fin(c1)){

    e = cr_elec(c1);

    cw_ins(c2, e);

    e = tuple_destroy(e);

    cr_av(c1);
  }
  
  c1 = cr_destroy(c1);
  c2 = cw_destroy(c2);

  return EXIT_SUCCESS;
}
